package com.xyj.concurrent;

import java.util.concurrent.CountDownLatch;

/**
 * countDownLatch使用
 * @author GuXiaoYao
 * @version 1.0.0
 * @since 2021/9/9
 */
public class T1 {

    public static void main(String[] args) throws InterruptedException {

        CountDownLatch countDownLatch=new CountDownLatch(10);
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "回家了");
                countDownLatch.countDown();
            },"线程"+i
            ).start();
        }
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName() + "回家了");
    }
}
